// pages/postalAddress/index.js

const app = getApp()

Page({
  data: {
  
  },
  onLoad:function(options){
    var userId = wx.getStorageSync('userId')
    var that = this;
    wx.request({
      url: app.globalData.basicUrl+'user/userData/'+userId,
      success:function(res){
        console.log(res);
        let addrData=res.data.data.userAddress
        that.setData({
          uname:addrData.userName,
          region:[addrData.province,addrData.city,addrData.district],
          add:addrData.addressDetail
        })
      }
    })
  },
  bindRegionChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      region: e.detail.value
    })
  },
  formSubmit: function (e) {
    console.log(e.detail.value);
    let data = e.detail.value;
    var adds = ''
    data.userId=app.globalData.userId
    // if(!this.data.uname&& !this.data.add && this.data.region.length==0){
    //   adds = "POST"
    // }else{
    //   adds ="PUT"
    // }
    wx.request({
      url: app.globalData.basicUrl+'user/userAddress',
      method:"POST",
      data:data,
      success:function(){

        wx.showToast({
          title: '添加成功',
          icon:"none"
        })
      }
    })
  },
})